﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
 
using System.Text;
using System.Windows.Forms;

namespace Demo
{
    public partial class ExcelLikeGrouping : DemoBaseUserControl
    {
        public ExcelLikeGrouping()
        {
            InitializeComponent();
            this.Title = "Excel 样式分组";
            this.Description = "Spread .NET  可以把行或列分组成大纲形式，就像Excel中一样。通过大纲的分组，可以创建多个级别的分组区域，可以编程控制组的展开和隐藏，以及自定义大纲显示在左边还是上面。本例中，可以单击“大纲按钮 (+ 和 - )”或“数字按钮”来展开或折叠大纲。";
        }
        private void ExcelLikeGrouping_Load_1(object sender, EventArgs e)
        {
            GetData();
            AddOutlines(true);
        }

        public void GetData()
        {
            FpSpread1.DataSource = 销售明细表TableAdapter.GetData();
        }
        public void AddOutlines(bool group)
        {
            if (group)
            {
                //Columns
                this.FpSpread1_Sheet1.AddRangeGroup(0, 4, false);
                this.FpSpread1_Sheet1.AddRangeGroup(0, 8, false);


                //Rows
                this.FpSpread1_Sheet1.AddRangeGroup(0, 30, true);
                this.FpSpread1_Sheet1.AddRangeGroup(0, 75, true);

               
            }
            else
            {
                //Columns
                this.FpSpread1_Sheet1.RemoveRangeGroup(0, 4, false);
                this.FpSpread1_Sheet1.RemoveRangeGroup(0, 8, false);


                //Rows
                this.FpSpread1_Sheet1.RemoveRangeGroup(0, 30, true);
                this.FpSpread1_Sheet1.RemoveRangeGroup(0, 75, true);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            FarPoint.Win.Spread.RangeGroupInfo[] rgi;
            int rowLevels = FpSpread1.ActiveSheet.GetRangeGroupLevels(true);

            for (int i = 1; i <= rowLevels; i++)
            {
                rgi = FpSpread1.ActiveSheet.GetRangeGroupInfo(i, true);
                foreach (FarPoint.Win.Spread.RangeGroupInfo ri in rgi)
                    FpSpread1.ActiveSheet.ExpandRangeGroup(ri, true, true);
            }
            int columnLevels = this.FpSpread1_Sheet1.GetRangeGroupLevels(false);

            for (int j = 1; j <= columnLevels; j++)
            {
                rgi = FpSpread1.ActiveSheet.GetRangeGroupInfo(j, false);
                foreach (FarPoint.Win.Spread.RangeGroupInfo ri in rgi)
                    FpSpread1.ActiveSheet.ExpandRangeGroup(ri, false, true);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            FarPoint.Win.Spread.RangeGroupInfo[] rgi;
            int rowLevels = FpSpread1.ActiveSheet.GetRangeGroupLevels(true);
            for (int i = 1; i <= rowLevels; i++)
            {
                rgi = FpSpread1.ActiveSheet.GetRangeGroupInfo(i, true);
                foreach (FarPoint.Win.Spread.RangeGroupInfo ri in rgi)
                    FpSpread1.ActiveSheet.ExpandRangeGroup(ri, true, false);
            }
            int columnLevels = this.FpSpread1_Sheet1.GetRangeGroupLevels(false);

            for (int j = 1; j <= columnLevels; j++)
            {
                rgi = FpSpread1.ActiveSheet.GetRangeGroupInfo(j, false);
                foreach (FarPoint.Win.Spread.RangeGroupInfo ri in rgi)
                    FpSpread1.ActiveSheet.ExpandRangeGroup(ri, false, false);
            }
        }


    }
}
